package com.dz.lm.service.manager.impl;

import com.dz.lm.common.constant.LmConstant;
import com.dz.lm.common.exception.DaoException;
import com.dz.lm.common.exception.ServiceException;
import com.dz.lm.common.util.*;
import com.dz.lm.common.utils.DateUtil;
import com.dz.lm.dao.appLogin.read.AppLoginDao;
import com.dz.lm.dao.business.read.ApplyProductDao;
import com.dz.lm.dao.comment.read.CommentDao;
import com.dz.lm.dao.log.read.LoginLogDao;
import com.dz.lm.dao.moneyBar.read.MoneyBarDao;
import com.dz.lm.dao.order.read.OrderDao;
import com.dz.lm.dao.product.read.AgentProductDao;
import com.dz.lm.dao.product.read.ProductDao;
import com.dz.lm.dao.user.write.CreditCardDao;
import com.dz.lm.dao.user.write.UserDao;
import com.dz.lm.dao.userproduct.read.UserProductDao;
import com.dz.lm.domain.order.Order;
import com.dz.lm.domain.userproduct.UserProduct;
import com.dz.lm.service.AbstractService;
import com.dz.lm.service.manager.ManagerService;
import com.google.common.collect.Maps;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Service
public class ManagerServiceImpl extends AbstractService implements ManagerService {

	public Logger logger = LogManager.getLogger(getClass());
	
    @Resource(name = "readCreditCardDao")
    private com.dz.lm.dao.user.read.CreditCardDao readCreditCardDao;
	
    @Resource(name = "writeCreditCardDao")
    private CreditCardDao creditCardDao;
    
    @Resource(name = "readUserDao")
    private com.dz.lm.dao.user.read.UserDao readUserDao;
	
    @Resource(name = "writeUserDao")
    private UserDao userDao;
    
    @Resource(name = "readLoginLogDao")
    private LoginLogDao loginLogDao;
    
    @Resource(name = "readAppLoginDao")
    private AppLoginDao rAppLoginDao;
    
    @Resource(name = "readMoneyBarDao")
    private MoneyBarDao moneyBarDao;
    
    @Resource(name = "readCommentDao")
    private CommentDao commentDao;
    
    @Resource(name = "readAccountDao")
    private com.dz.lm.dao.account.read.AccountDao readAccountDao;
    
    @Resource(name = "writeAccountDao")
    private com.dz.lm.dao.account.write.AccountDao writeAccountDao;
    
    @Resource(name = "writeMoneyBarManagerDao")
    private com.dz.lm.dao.user.write.MoneyBarManagerDao writeMoneyBarManagerDao;
    
    @Resource(name = "readMoneyBarManagerDao")
    private com.dz.lm.dao.user.read.MoneyBarManagerDao readMoneyBarManagerDao;
    
    @Resource(name = "writeMoneyBarDao")
    private com.dz.lm.dao.moneyBar.write.MoneyBarDao writeMoneyBarDao;
    
    @Resource(name = "readProductDao")
    private ProductDao productDaoRead;
    
    @Resource(name = "readApplyProductDao")
    private ApplyProductDao applyProductDaoRead;

    @Resource(name = "readOrderDao")
    private OrderDao orderDaoRead;

    @Resource(name = "writeApplyProductDao")
    private com.dz.lm.dao.business.write.ApplyProductDao applyProductDaoWrite;
    
    @Resource(name = "readAgentProductDao")
    private AgentProductDao agentProductDaoRead;
    
    @Resource(name = "writeAgentProductDao")
    private com.dz.lm.dao.product.write.AgentProductDao agentProductDaoWrite;
    
    @Resource(name = "writeProductDao")
    private com.dz.lm.dao.product.write.ProductDao productDaoWrite;
	@Resource(name = "readUserProductDao")
	private UserProductDao readUserProductDao;
    @Resource
    private com.dz.lm.dao.order.read.OrderDao readOrderDao;
    
    @Resource
    private com.dz.lm.dao.product.read.ProductDao readProductDao;
    
    @Resource
    private com.dz.lm.dao.order.write.OrderDao writeOrderDao;
    
    @Resource
    private com.dz.lm.dao.order.read.ProductOrderDao readProductOrderDao;
    
    @Resource
    private com.dz.lm.dao.order.write.ProductOrderDao writeProductOrderDao;
    
    @Resource
    private com.dz.lm.dao.business.write.ApplyProductDao wApplyProductDao;
    
    @Resource
    private com.dz.lm.dao.reminder.write.ReminderDao writeReminderDao;

    @Resource
    private WxPay wxPay;
    
    public int updateAuthUserInfo(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
    		count = userDao.updateAuthUserInfo(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
    
    public int orgAuthManager(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
    		count = writeMoneyBarManagerDao.modifyMoneyBarManager(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
    
    public List<Map<String, Object>> searchMoneyBars(Map<String, Object> param) throws ServiceException {
    	List<Map<String, Object>> moneyBars = null;
    	try {
    		moneyBars = moneyBarDao.searchMoneyBars(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return moneyBars;
    }
    
    public Map<String, Object> addMoneyBarManager(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	int count = 0;
    	try {
    		userDao.updateManagerInfo(param);
    		count = userDao.updateUserDetailByUserId(param);
    		if (count == 0) {
        		userDao.insertUserDetail(param);
    		}
    		count = writeMoneyBarManagerDao.addMoneyBarManager(param);
    		if (count == 1) {
    			Map<String, Object> user = rAppLoginDao.qryUserInfoByUserId(param);
        	    retMap.put("user", user);
    		}
    	    retMap.put("count", count);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return retMap;
    }
    
    public int addCreditCardInfo(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
    		creditCardDao.updateCreditCardInfo(param);
    		if (count == 0) {
    			count = creditCardDao.addCreditCardInfo(param);
        		if (count == 1) {
        			Map<String, Object> creditCard = readCreditCardDao.qryCreditCardIdByUserId(param);
        			count = (int)creditCard.get("creditCardId");
            		userDao.updateManagerInfo(param);
        		}
    		}
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
    
    public int updateCreditCardInfo(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
    		count = creditCardDao.updateCreditCardInfo(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
    
    public Map<String, Object> qryCreditCardInfo(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> creditCardInfo = null;
    	try {
    		creditCardInfo = readCreditCardDao.qryCreditCardInfo(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return creditCardInfo;
    }
    
    public Map<String, Object> previewCreditCardInfo(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> creditCardInfo = null;
    	try {
    		String type = param.get("type") != null ? param.get("type").toString() : "1";
    		if ("1".equals(type)) {
    			creditCardInfo = readCreditCardDao.qryCreditCardIdByUserId(param);
    		} else {
    			creditCardInfo = readCreditCardDao.previewCreditCardInfo(param);
    		}
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return creditCardInfo;
    }
    
    public Map<String, Object> qryMyProductList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> productList = null;
    	Integer count = 0;
		try {
			//查询类别
			String type = param.get("type") != null? param.get("type").toString() : "1";
			if ("1".equals(type)) {
				//查询当前用户创建的产品列表
				productList = productDaoRead.qryMyProductList(param);
				//查询当前用户创建的产品数据条数
				count = productDaoRead.qryMyProductListCount(param);
			} else {
				//查询当前用户代理的产品列表
				productList = agentProductDaoRead.qryMyAgentProductList(param);
				//查询当前用户搭理的产品数据条数
				count = agentProductDaoRead.qryMyAgentProductListCount(param);
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("productList", productList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryUserAgentProductList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> productList = null;
    	Integer count = 0;
		try {
			//查询当前用户代理的产品列表
			productList = agentProductDaoRead.qryUserAgentProductList(param);
			//查询当前用户搭理的产品数据条数
			count = agentProductDaoRead.qryUserAgentProductListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("productList", productList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryMyAgentList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> agentList = null;
    	Integer count = 0;
		try {
			//查询当前用户的代理人列表
			agentList = agentProductDaoRead.qryMyAgentList(param);
			//查询当前用户的代理人条数
			count = agentProductDaoRead.qryMyAgentListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("agentList", agentList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryLowLevelAgentList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> agentList = null;
    	Integer count = 0;
    	int totalApplyCount = 0;
		try {
			//查询当前用户代理的产品的下级列表
			agentList = agentProductDaoRead.qryLowLevelAgentList(param);
			//查询当前用户代理的产品的下级条数
			count = agentProductDaoRead.qryLowLevelAgentListCount(param);
			//查询当前用户代理的产品的累计进件单数
			Map<String, Object> applyCount = agentProductDaoRead.qryTotalApplyCount(param);
			if (applyCount != null && !applyCount.isEmpty()) {
				totalApplyCount = applyCount.get("totalApplyCount") != null ? Integer.valueOf(applyCount.get("totalApplyCount").toString()) : 0;
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("agentList", agentList);
		retMap.put("totalApplyCount", totalApplyCount);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryAgentProductApplyList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> applyList = null;
    	Integer count = 0;
		try {
			//查询某个代理产品进件明细列表
			applyList = agentProductDaoRead.qryAgentProductApplyList(param);
			//查询某个代理产品进件明细条数
			count = agentProductDaoRead.qryAgentProductApplyListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("applyList", applyList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryUserAgentProductApplyList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> applyList = null;
    	Integer count = 0;
		try {
			//获取我的代理人下【累计推送】信息列表
			applyList = agentProductDaoRead.qryUserAgentProductApplyList(param);
			//获取我的代理人下【累计推送】信息条数
			count = agentProductDaoRead.qryUserAgentProductApplyListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("applyList", applyList);
		retMap.put("count", count);
    	return retMap;
    }

    public Map<String, Object> qryMyAgentProductApplyList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> applyList = null;
    	Integer count = 0;
		try {
			//查询某个代理产品进件明细列表
			applyList = agentProductDaoRead.qryMyAgentProductApplyList(param);
			//查询某个代理产品进件明细条数
			count = agentProductDaoRead.qryMyAgentProductApplyListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("applyList", applyList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public int delMyProduct(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
			//查询类别
			String type = param.get("type") != null? param.get("type").toString() : "1";
			if ("1".equals(type)) {
				//删除用户创建的产品数据
				count = productDaoWrite.delMyProduct(param);
			} else {
				//删除用户代理的产品数据
				count = agentProductDaoWrite.delMyAgentProduct(param);
			}
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
    
    public Map<String, Object> qryMyProductApplyList(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	List<Map<String, Object>> productApplyList = null;
    	Integer count = 0;
		try {
			//查询类别
			String type = param.get("type") != null? param.get("type").toString() : "1";
			if ("1".equals(type)) {
				//获取创建的产品的申请信息列表
				productApplyList = productDaoRead.qryMyProductApplyList(param);
				//获取创建的产品的申请信息条数
				count = productDaoRead.qryMyProductApplyListCount(param);
			} else {
				//获取代理的产品的申请信息列表
				productApplyList = agentProductDaoRead.qryMyAgentProductApplyList(param);
				//获取代理的产品的申请信息条数
				count = agentProductDaoRead.qryMyAgentProductApplyListCount(param);
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("productApplyList", productApplyList);
		retMap.put("count", count);
    	return retMap;
    }
    
    public Map<String, Object> qryApplyInfo(Map<String, Object> param) throws ServiceException {
    	Map<String, Object> retMap = new HashMap<String, Object>();
    	Map<String, Object> applyInfo = null;
		Map<String, Object> creditCardInfo = null;
		try {
			//查询用户申请信息
			applyInfo = applyProductDaoRead.qryApplyInfo(param);
			Object productId = applyInfo.get("productId");
			Map<String, Object> insertParam = new HashMap<String, Object>();
			insertParam.put("userId", param.get("userId"));
			insertParam.put("applyId", param.get("applyId"));
        	if ("8".equals(param.get("type"))) {
        		insertParam.put("type", "8");
        	} else {
	        	if (productId != null && !"".equals(productId)) {
					insertParam.put("type", "4");
					//取消红点按applyId删除数据即可
				} else {
					insertParam.put("type", "5");
					//取消红点按applyId删除数据即可
				}
        	}
			writeReminderDao.delReminder(insertParam);
			if (applyInfo != null 
					&& !applyInfo.isEmpty() 
					&& applyInfo.get("creditCardId") != null 
					&& !"".equals(applyInfo.get("creditCardId").toString())) {
				param.put("userId", applyInfo.get("userId"));
				if ("1".equals(applyInfo.get("state")) || "3".equals(applyInfo.get("state"))) {//state（1: 表示已接单 3:放款成功)
					creditCardInfo = readCreditCardDao.previewCreditCardInfo2(param);
				} else {
					creditCardInfo = readCreditCardDao.previewCreditCardInfo(param);
				}
			}
			retMap.put("applyInfo", applyInfo);
			retMap.put("creditCardInfo", creditCardInfo);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
    	return retMap;
    }
    
    public Map<String, Object> processApplyRecord(Map<String, Object> qryparam) throws ServiceException{
    	Map<String, Object> retData = new HashMap<String, Object>();
    	Map<String, Object> updateMap = new HashMap<String, Object>();
    	Object applyId = qryparam.get("applyId");
    	String state = qryparam.get("state").toString();
    	String loanAmount = qryparam.get("loanAmount") == null? "0.00" : qryparam.get("loanAmount").toString();
		Map<String, Object> insertParam = new HashMap<String, Object>();
    	try {
    		//获取产品的支付金额与支付比率
        	Map<String, Object> payInfo = applyProductDaoRead.qryAgentProductPayByApplyId(qryparam);
        	Object applyUserId = payInfo.get("applyUserId");
    		//1:已接单，2:已拒绝，3:放款成功
    		if ("1".equals(state)) {
            	if (payInfo != null && !payInfo.isEmpty()) {
            		// 个人产品不需要支付直接更新审核状态
        			if (personalProductProcess(payInfo)) {
                		payInfo.put("state", state);
                		int count = wApplyProductDao.callbackPayResult(payInfo);
                		if (count == 1) {
        	    			retData.put("result", "00");
        	    			retData.put("message", "接单成功");
                		} else {
        	    			retData.put("result", "01");
        	    			retData.put("message", "接单失败");
                		}
    	    			return retData;
        			}
            		loanAmount = payInfo.get("payAmount") == null? "0.00" : payInfo.get("payAmount").toString();
            		double amount = Double.valueOf(loanAmount);
            		String body = LmConstant.LM_PAY_BODY_REBATE;
            		//支付类型（1：高亮显示，2：自动刷新，3：高亮及自动刷新 ，4：接单支付，5：放款支付）
            		qryparam.put("amount", amount);
        			qryparam.put("body", body);
        			qryparam.put("device_info", qryparam.get("deviceId"));
        			qryparam.put("spbill_create_ip", qryparam.get("ip"));
        			qryparam.put("busPayType", "4");
        			qryparam.put("productClass", "2");
        			qryparam.put("payResult", "UNPAID");//未支付
                	try {
                		if (amount > 0.00) {
                    		Map<String, Object> param = new HashMap<String, Object>();
                    		Order order = new Order();
                    		Map<String, Object> account = readAccountDao.qryAccountInfoByUserId(qryparam);
                    		order.setUserId(Integer.valueOf(qryparam.get("userId").toString()));
                    		if(account == null || account.get("accountId") == null || "".equals(account.get("accountId"))) {
                    	    	//创建账户信息
                    			qryparam.put("property", "1");//账户性质（1：个人；2：企业）
                    			qryparam.put("state", "1");//状态（1 正常 2 冻结 3 注销）
                        		//无数据，新增一条
                        		writeAccountDao.addAccount(qryparam);
                    		}
                    		account = readAccountDao.qryAccountInfoByUserId(qryparam);
                    		String orderId = getOrderId();
                    		order.setOrderId(orderId);
                    		order.setAccountId(Integer.valueOf(account.get("accountId").toString()));
                    		order.setAmount((Double) qryparam.get("amount"));
                    		order.setBody(qryparam.get("body").toString());
                    		order.setOrderType("2");
                    		order.setPayType("1");
                    		order.setState("21");
                    		writeOrderDao.addOrder(order);
                    		
                    		param.put("device_info", qryparam.get("device_info"));
                    		param.put("body", qryparam.get("body").toString());
                    		param.put("out_trade_no", orderId);
                    		BigDecimal bigAmount = new BigDecimal(qryparam.get("amount").toString());
                    		BigDecimal big100 = new BigDecimal(100);
                    		param.put("total_fee", bigAmount.multiply(big100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
                    		param.put("spbill_create_ip", qryparam.get("spbill_create_ip"));
                    		retData = wxPay.unifiedOrder(param);
                    		Map<String, Object> orderMap = new HashMap<String, Object>();
                    		if ("SUCCESS".equals(retData.get("return_code"))) {
                	    		String sign = wxPay.getSign(retData);
                	    		String reqSign = retData.get("sign") != null ? retData.get("sign").toString() : "";
                				logger.info("sign=" + sign + ",regSign=" + reqSign);
                	    		if (!reqSign.equals(sign)) {
                	    			retData = new HashMap<String, Object>();
                	    			retData.put("result", "01");
                	    			retData.put("message", "订单支付返回值验签失败");
                	    			return retData;
                	    		}
                	    		if ("SUCCESS".equals(retData.get("result_code"))) {
                	    			String prepay_id = retData.get("prepay_id").toString();
                	        		orderMap.put("orderId", orderId);
                	        		orderMap.put("tradeId", prepay_id);
                	        		orderMap.put("state", "22");//支付中
                	        		orderMap.put("returnData", retData.toString());//支付中
                	    		}
                	    		try {
                					writeOrderDao.updateOrder(orderMap);
                					orderMap.put("applyId", applyId);
                					orderMap.put("busPayType", qryparam.get("busPayType"));
                					orderMap.put("productClass", qryparam.get("productClass"));
                					orderMap.put("payResult", qryparam.get("payResult"));
                					writeProductOrderDao.addProductOrder(orderMap);
                				} catch (DaoException e) {
                					e.printStackTrace();
                				}
                    		}
                    		retData.put("orderInfo", wxPay.getOrderParam(retData));
        	    			retData.put("result", "00");
        	    			retData.put("message", "接单成功");
                		} else {
                    		updateMap.put("applyId", applyId);
                    		updateMap.put("state", state);
                			wApplyProductDao.callbackPayResult(updateMap);
        	    			retData.put("result", "00");
        	    			retData.put("message", "接单成功");
                		}
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
                	return retData;
            	}
    		} else if ("3".equals(state)) {
            	if (payInfo != null && !payInfo.isEmpty()) {
        			if (personalProductProcess(payInfo)) {
                		payInfo.put("state", state);
                		payInfo.put("loanAmount", loanAmount);
                		int count = wApplyProductDao.callbackPayResult(payInfo);
                		if (count == 1) {
        	    			retData.put("result", "00");
        	    			retData.put("message", "审核成功");
                    		insertParam = new HashMap<String, Object>();
                    		insertParam.put("userId", applyUserId);
                    		insertParam.put("applyId", applyId);
                    		insertParam.put("type", "8");
                    		writeReminderDao.addReminder(insertParam);
            		    	insertParam.put("platform", qryparam.get("platform"));
            		    	Runnable runable = new AsyncThread(insertParam);
            		    	runable.run();
                		} else {
        	    			retData.put("result", "01");
        	    			retData.put("message", "审核失败");
                		}
    	    			return retData;
        			}
            		String payRate = payInfo.get("payRate") == null? "0.00" : payInfo.get("payRate").toString();
            		BigDecimal bigLoanAmount = new BigDecimal(loanAmount);
            		BigDecimal bigPayRate = new BigDecimal(payRate);
            		BigDecimal big100 = new BigDecimal(100);
            		//loanAmount*payRate/100
            		double amount = Double.valueOf(bigLoanAmount.multiply(bigPayRate).divide(big100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
            		String body = LmConstant.LM_PAY_BODY_TURNOVER;
            		//支付类型（1：高亮显示，2：自动刷新，3：高亮及自动刷新 ，4：接单支付，5：放款支付）
            		qryparam.put("amount", amount);
        			qryparam.put("body", body);
        			qryparam.put("device_info", qryparam.get("deviceId"));
        			qryparam.put("spbill_create_ip", qryparam.get("ip"));
        			qryparam.put("busPayType", "5");
        			qryparam.put("productClass", "2");
        			qryparam.put("payResult", "UNPAID");//未支付
                	try {
                		if (amount > 0.00) {
                    		Map<String, Object> param = new HashMap<String, Object>();
                    		Order order = new Order();
                    		Map<String, Object> account = readAccountDao.qryAccountInfoByUserId(qryparam);
                    		order.setUserId(Integer.valueOf(qryparam.get("userId").toString()));
                    		String orderId = getOrderId();
                    		order.setOrderId(orderId);
                    		order.setAccountId(Integer.valueOf(account.get("accountId").toString()));
                    		order.setAmount((Double) qryparam.get("amount"));
                    		order.setBody(qryparam.get("body").toString());
                    		order.setOrderType("2");
                    		order.setPayType("1");
                    		order.setState("21");
                    		writeOrderDao.addOrder(order);
                    		
                    		param.put("device_info", qryparam.get("device_info"));
                    		param.put("body", qryparam.get("body").toString());
                    		param.put("out_trade_no", orderId);
                    		BigDecimal bigAmount = new BigDecimal(qryparam.get("amount").toString());
                    		param.put("total_fee", bigAmount.multiply(big100).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
                    		param.put("spbill_create_ip", qryparam.get("spbill_create_ip"));
                    		retData = wxPay.unifiedOrder(param);
                    		Map<String, Object> orderMap = new HashMap<String, Object>();
                    		if ("SUCCESS".equals(retData.get("return_code"))) {
                	    		String sign = wxPay.getSign(retData);
                	    		String reqSign = retData.get("sign") != null ? retData.get("sign").toString() : "";
                				logger.info("sign=" + sign + ",regSign=" + reqSign);
                	    		if (!reqSign.equals(sign)) {
                	    			retData = new HashMap<String, Object>();
                	    			retData.put("result", "01");
                	    			retData.put("message", "订单支付返回值验签失败");
                	    			return retData;
                	    		}
                	    		if ("SUCCESS".equals(retData.get("result_code"))) {
                	    			String prepay_id = retData.get("prepay_id").toString();
                	        		orderMap.put("orderId", orderId);
                	        		orderMap.put("tradeId", prepay_id);
                	        		orderMap.put("state", "22");//支付中
                	        		orderMap.put("returnData", retData.toString());//支付中
                	    		}
                	    		try {
                					writeOrderDao.updateOrder(orderMap);
                					orderMap.put("applyId", applyId);
                					orderMap.put("busPayType", qryparam.get("busPayType"));
                					orderMap.put("productClass", qryparam.get("productClass"));
                					orderMap.put("payResult", qryparam.get("payResult"));
                					writeProductOrderDao.addProductOrder(orderMap);
                				} catch (DaoException e) {
                					e.printStackTrace();
                				}
                    		}
                    		retData.put("orderInfo", wxPay.getOrderParam(retData));
                    		updateMap.put("applyId", applyId);
                    		updateMap.put("loanAmount", loanAmount);
                			wApplyProductDao.callbackPayResult(updateMap);
        	    			retData.put("result", "00");
        	    			retData.put("message", "审核成功");
                		} else {
                			updateMap.put("state", state);
                			updateMap.put("applyId", applyId);
                    		updateMap.put("loanAmount", loanAmount);
                			wApplyProductDao.callbackPayResult(updateMap);
        	    			retData.put("result", "00");
        	    			retData.put("message", "审核成功");
                		}
                		insertParam = new HashMap<String, Object>();
                		insertParam.put("userId", applyUserId);
                		insertParam.put("applyId", applyId);
                		insertParam.put("type", "8");
                		writeReminderDao.addReminder(insertParam);
        		    	insertParam.put("platform", qryparam.get("platform"));
        		    	Runnable runable = new AsyncThread(insertParam);
        		    	runable.run();
            		} catch (Exception e) {
            			e.printStackTrace();
            		}
                	return retData;
            	}
    		} else {
        		//申请记录的拒绝或确认接单
    			int count = applyProductDaoWrite.processApplyRecord(qryparam);
    			if (count == 1) {
	    			retData.put("result", "00");
	    			retData.put("message", "审核成功");
            		insertParam = new HashMap<String, Object>();
            		insertParam.put("userId", applyUserId);
            		insertParam.put("applyId", applyId);
            		insertParam.put("type", "8");
            		writeReminderDao.addReminder(insertParam);
    		    	insertParam.put("platform", qryparam.get("platform"));
    		    	Runnable runable = new AsyncThread(insertParam);
    		    	runable.run();
    			} else {
	    			retData.put("result", "01");
	    			retData.put("message", "审核失败");
    			}
    		}
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return retData;
    }
    
    private boolean personalProductProcess(Map<String, Object> payInfo) {
    	boolean result = false;
    	if (payInfo != null && payInfo.get("productId") != null && !"".equals(payInfo.get("productId"))) {
    		result = true;
    	}
    	return result;
    }
    
    @Override
	public int deleteMoneyBarAgent(Map<String, Object> param) throws ServiceException {
		try {
			return writeMoneyBarManagerDao.deleteMoneyBarAgent(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
	}

	@Override
	public Map<String, Object> getManagerList(Map<String, Object> qryParam) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> managerList = null;
		int count = 0;
		try {
			// 返回数据明细
			managerList = readMoneyBarManagerDao.getManagerList(qryParam);
			// 返回数据总条数
			count = readMoneyBarManagerDao.getManagerListCount(qryParam);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("managerList", managerList);
		retMap.put("managerListCount", count);
		return retMap;
	}

	@Override
	public int doAuthManager(Map<String, Object> param) throws ServiceException {
		try {
			//删除提醒信息
			Map<String, Object> insertParam = new HashMap<String, Object>();
			insertParam.put("userId", param.get("auditUserId"));
			insertParam.put("type", "1");
			insertParam.put("operatedUserId", param.get("userId"));
			writeReminderDao.delReminder(insertParam);
			//state 审批状态 （1：审核通过，2：审核拒绝）
			String orgAuthFlag = "0";//机构认证标识（0：未认证 1：已认证）
			if ("1".equals(String.valueOf(param.get("state")))) {
				orgAuthFlag = "1";
			}
			param.put("orgAuthFlag", orgAuthFlag);
			userDao.updateManagerInfo(param);
			return writeMoneyBarManagerDao.doAuthManager(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
	}

	@Override
	public int deleteBarManager(Map<String, Object> param) throws ServiceException {
		int count = 0;
		try {
			if (String.valueOf(param.get("activeUserId")).equals(String.valueOf(param.get("userId")))) {
				Map<String, Object> moneyBar = moneyBarDao.getMoneyBarStateById(param);
				Map<String, Object> insertParam = new HashMap<String, Object>();
				insertParam.put("userId", moneyBar.get("createUserId"));
				insertParam.put("type", "1");
				insertParam.put("manageUserId", param.get("activeUserId"));
			}
			count = writeMoneyBarManagerDao.deleteBarManager(param);
			if (count == 1) {
				param.put("orgAuthFlag", "0");//机构认证更新为未认证
				userDao.updateManagerInfo(param);
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		return count;
	}

	@Override
	public Map<String, Object> qryBarFavoriteListByUser(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> barFavoriteList = null;
		int count = 0;
		try {
			// 返回数据明细
			barFavoriteList = readMoneyBarManagerDao.getBarFavoriteListByUser(param);
			// 返回数据总条数
			count = readMoneyBarManagerDao.getBarFavoriteListCountByUser(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("barFavoriteList", barFavoriteList);
		retMap.put("barFavoriteListCount", count);
		return retMap;
	}

	@Override
	public Map<String, Object> qryBarFavoriteListByBar(Map<String, Object> param) throws ServiceException {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public Map<String, Object> qryUserSetInfo(Map<String, Object> param) throws ServiceException {
		Map<String, Object> userInfo = new HashMap<String, Object>();
		try {
			// 返回数据
			userInfo = rAppLoginDao.qryUserSetInfo(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		return userInfo;
	}
	
	@Override
	public int userSet(Map<String, Object> param)throws ServiceException {
    	int count = 0;
    	try {
    		//修改设置页内容
			count = userDao.userSet(param);	
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
	}

	@Override
	public Map<String, Object> qryUserHomeInfo(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retData = new HashMap<String, Object>();
		Map<String, Object> userInfo = null;
		Map<String, Object> orgAuthInfo = null;
		try {
			//返回数据
			Object userId = param.get("userId");
			Object activeUserId = param.get("activeUserId");
			String userIds = "1000000,1000001,1000002,1000005,1000012,1000024,1000025,1000027,1000028";
			if (Integer.valueOf(userId.toString()) < 1000000 || activeUserId.equals(userId) || userIds.indexOf(userId.toString()) < 0) {
				userInfo = rAppLoginDao.qryUserHomeInfo(param);
				orgAuthInfo = rAppLoginDao.qryUserOrgAuthInfo(param);
				if ("1".equals(userInfo.get("perOpenStoreFlag"))) {
					userInfo.put("perStoreUrl", FileLoadUtil.getPerStoreUrl() + userId);
				} else {
					userInfo.put("perStoreUrl", "");
				}
				retData.put("userInfo", userInfo);
				retData.put("orgAuthInfo", orgAuthInfo);
			} else {
				userInfo = rAppLoginDao.qryUserHomeInfoB(param);
				if ("1".equals(userInfo.get("perOpenStoreFlag"))) {
					userInfo.put("perStoreUrl", FileLoadUtil.getPerStoreUrl() + userId);
				} else {
					userInfo.put("perStoreUrl", "");
				}
				retData.put("userInfo", userInfo);
				retData.put("orgAuthInfo", orgAuthInfo);
			}

		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		return retData;
	}

	@Override
	public Map<String, Object> qryUserHomeProducts(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> productList = null;
		int count = 0;
    	//计算3分钟之前的时间戳类型的参数(180000为毫秒数)
    	Date day = new Date();
    	long beforeTenMin = day.getTime();// - 180000;
    	Timestamp ts = new Timestamp(beforeTenMin);
    	param.put("createTime", ts);
		try {
			Object userId = param.get("userId");
			Object activeUserId = param.get("activeUserId");
			String userIds = "1000000,1000001,1000002,1000005,1000012,1000024,1000025,1000027,1000028";
			if (Integer.valueOf(userId.toString()) < 1000000 || activeUserId.equals(userId) || userIds.indexOf(userId.toString()) < 0) {
				// 返回数据明细
				productList = productDaoRead.qryUserHomeProducts(param);
				for (Map<String, Object> product : productList) {
					Timestamp times = (Timestamp) product.get("times");
					product.put("times", DateUtil.getTimes(times));
				}
				// 返回数据总条数
				count = productDaoRead.qryUserHomeProductsCount(param);
			}
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("productList", productList);
		retMap.put("count", count);
		return retMap;
	}
	
	@Override
	public Map<String, Object> qryManageAuthInfo(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retData = new HashMap<String, Object>();
		Map<String, Object> userInfo = null;
		Map<String, Object> manageAuthInfo = null;
		try {
			// 返回数据
			userInfo = rAppLoginDao.qryUserInfoByUserId(param);
			manageAuthInfo = rAppLoginDao.qryManageAuthInfo(param);
			retData.put("loginName", userInfo.get("loginName"));
			retData.put("profile", userInfo.get("profile"));
			retData.put("manageFlag", userInfo.get("manageFlag"));
			retData.put("orgAuthFlag", userInfo.get("orgAuthFlag"));
			retData.put("manageAuthInfo", manageAuthInfo);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		return retData;
	}
	
	@Override
	public Map<String, Object> modifyManageAuthInfo(Map<String, Object> param)throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
    	int count = 0;
    	try {
    		userDao.updateUserDetailByUserId(param);
    		count = writeMoneyBarManagerDao.modifyMoneyBarManager(param);
    		if (count == 1) {
    			Map<String, Object> user = rAppLoginDao.qryUserInfoByUserId(param);
    			retMap.put("user", user);
    		}
    	    retMap.put("count", count);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return retMap;
    }
	
	@Override
	public Map<String, Object> qryUserHomeComments(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> commentList = null;
		int count = 0;
		try {
			// 返回数据明细
			commentList = commentDao.qryCommentsByUserId(param);
			// 返回数据总条数
			count = commentDao.qryCommentsByUserIdCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("commentList", commentList);
		retMap.put("count", count);
		return retMap;
	}
	
	@Override
	public Map<String, Object> qryMyApplyList(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> applyList = null;
		int count = 0;
		try {
			// 返回数据明细
			applyList = applyProductDaoRead.qryMyApplyList(param);
			// 返回数据总条数
			count = applyProductDaoRead.qryMyApplyListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("applyList", applyList);
		retMap.put("count", count);
		return retMap;
	}

	@Override
	public Map<String, Object> qry1LevelAgentProductList(Map<String, Object> qryParam) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> _1LevelAgentProductList = null;
		int count = 0;
		try {
			// 返回数据明细
			_1LevelAgentProductList = agentProductDaoRead.qry1LevelAgentProductList(qryParam);
			for(Map<String, Object> product :_1LevelAgentProductList) {
				product.put("applyCount", agentProductDaoRead.qry1LevelAgentProductApplyCount(Integer.valueOf(product.get("productId").toString())));
			}
			// 返回数据总条数
			count = agentProductDaoRead.qry1LevelAgentProductListCount(qryParam);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("_1LevelAgentProductList", _1LevelAgentProductList);
		retMap.put("count", count);
		return retMap;
	}

	@Override
	public int add2LevelAgent(Map<String, Object> param) throws ServiceException {
		return 0;
	}

	@Override
	public int add2LevelAgentProduct(Map<String, Object> param) throws ServiceException {
		try {
			List<Map<String, Object>> _1levelAgentProductList = agentProductDaoRead.qryAll1LevelAgentProductList(param);
			List<Map<String, Object>> _2levelAgentProductList = agentProductDaoRead.qry2LevelAgentProductList(param);
			List<Map<String, Object>> _2levelAgentProductListTemp = new ArrayList<Map<String, Object>>();
			for (Map<String, Object> _2levelAgentProduct : _2levelAgentProductList) {
				for (Map<String, Object> _1levelAgentProduct : _1levelAgentProductList) {
					if(!_2levelAgentProduct.get("agentProductId").equals(_1levelAgentProduct.get("productId"))) {
						Map<String, Object> _2levelAgentProductTemp = new HashMap<String, Object>();
						_2levelAgentProductTemp.put("agentId", param.get("userId"));
						_2levelAgentProductTemp.put("agentProductId", _1levelAgentProduct.get("productId"));
						_2levelAgentProductTemp.put("originalProductId", _1levelAgentProduct.get("originalProductId"));
						_2levelAgentProductListTemp.add(_2levelAgentProductTemp);
					}
				}
			}
			// 每批次插入数量
			int batchCount = 10;
			// 游标
			int index = 0;
			// 返回
			int returnCount = 0;
			for (;;) {
				if (index + batchCount >= _2levelAgentProductListTemp.size()) {
					returnCount = productDaoWrite.add2levelAgentProductList(
							_2levelAgentProductListTemp.subList(index, _2levelAgentProductListTemp.size()));
					break;
				} else {
					List<Map<String, Object>> _2LevelAgentProductSubList = _2levelAgentProductListTemp.subList(index,
							index + batchCount);
					returnCount = returnCount + productDaoWrite.add2levelAgentProductList(_2LevelAgentProductSubList);
					index = index + batchCount;
				}
			}
			return returnCount;
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
	}
	
	@Override
	public Map<String, Object> qryMyAccountInfo(Map<String, Object> param) throws ServiceException {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Map<String, Object>> tradeList = null;
		int count = 0;
		try {
			Map<String, Object> account = readAccountDao.qryMyAccountByUserId(param);
			if (account != null && !account.isEmpty()) {
				retMap.put("cashAmount", account.get("cashAmount"));//余额
				retMap.put("incomeAmount", account.get("incomeAmount"));//收入
				retMap.put("payAmount", account.get("payAmount"));//支出
				retMap.put("cashWithdrawal", account.get("cashWithdrawal"));//提现
			} else {
				retMap.put("cashAmount", 0.00);
				retMap.put("incomeAmount", 0.00);
				retMap.put("payAmount", 0.00);
			}
			// 返回数据明细
			tradeList = orderDaoRead.qryTradeList(param);
			String tradeType = "";
			String tag = "";
			String tradeState = "";
			Map p = new HashMap();
			Map user = null;
			for (Map<String, Object> trade : tradeList) {
				/*if("2".equals(trade.get("tradeType")) || "3".equals(trade.get("tradeType"))) {
					tradeType = "支出";
					tag = "- ";
				} else {
					tradeType = "收入";
					tag = "+ ";
				}*/
				p.clear();
				switch (trade.get("tradeType").toString()){
					case "1":
						tradeType = "收入";
						tag = "+ ";
						break;
					case "2":
						tradeType = "支出";
						tag = "- ";
						break;
					case "3":
						tradeType = "提现";
						tag = " ";
						break;
					case "4":
						tradeType = "支出-代理费";
						tag = "- ";
						break;
					case "5":
						p.put("userId", StringUtil.getInt(trade.get("gatherUserId"),0));
						user = rAppLoginDao.qryUserInfoByUserId(p);
                        String name = user != null ? "-" + user.get("loginName").toString() : "";

                        tradeType = "支出-返点"+name;
						tag = "- ";
						break;
					case "6":
						p.put("userId", StringUtil.getInt(trade.get("gatherUserId"),0));
						user = rAppLoginDao.qryUserInfoByUserId(p);
                        String name1 = user != null ? "-" + user.get("loginName").toString() : "";
                        tradeType = "收入-代理费" +name1;
						tag = "+ ";
						break;
					case "7":
						p.put("userId", StringUtil.getInt(trade.get("gatherUserId").toString(),0));
						user = rAppLoginDao.qryUserInfoByUserId(p);
                        String name2 = user != null ? "-" + user.get("loginName").toString() : "";

                        tradeType = "收入-返点"+ name2;
						tag = "+ ";
						break;
					case "8":
						p.put("userId", StringUtil.getInt(trade.get("gatherUserId").toString(),0));
						user = rAppLoginDao.qryUserInfoByUserId(p);
						String name3 = user != null ? "-" + user.get("loginName").toString() : "";

						tradeType = "收入-代理费退回"+ name3;
						tag = "+ ";
						break;
					case "9":
						UserProduct produnct = readUserProductDao.selectByPrimaryKey(StringUtil.getInt(trade.get("gatherUserId").toString(), 0));
						String name4 = produnct != null ? "-" + produnct.getProductName() : "";

						tradeType = "支出-商品支付"+ name4;
						tag = "- ";
						break;
					case "10":
						p.put("userId", StringUtil.getInt(trade.get("gatherUserId").toString(),0));
						user = rAppLoginDao.qryUserInfoByUserId(p);
						String name5 = user != null ? "-" + user.get("loginName").toString() : "";

						tradeType = "收入-商品支付"+ name5;
						tag = "+ ";
						break;
					case "11":
						UserProduct produnct1 = readUserProductDao.selectByPrimaryKey(StringUtil.getInt(trade.get("gatherUserId").toString(), 0));
						String name8 = produnct1 != null ? "-" + produnct1.getProductName() : "";

						tradeType = "收入-商品退款"+ name8;
						tag = "+ ";
						break;
				}
				if("21".equals(trade.get("state")) || "31".equals(trade.get("state"))) {
					tradeState = "待处理";
				} else if("12".equals(trade.get("state")) || "22".equals(trade.get("state")) || "32".equals(trade.get("state"))) {
					tradeState = "交易中";
				} else if("13".equals(trade.get("state")) || "23".equals(trade.get("state")) || "33".equals(trade.get("state")) || "43".equals(trade.get("state"))) {
					tradeState = "交易成功";
				} else if("14".equals(trade.get("state")) || "24".equals(trade.get("state")) || "34".equals(trade.get("state"))) {
					tradeState = "交易失败";
				}
				trade.put("tradeType", tradeType);
				trade.put("amount", tag + trade.get("amount"));
				trade.put("state", tradeState);
			}
			// 返回数据总条数
			count = orderDaoRead.qryTradeListCount(param);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		retMap.put("tradeList", tradeList);
		retMap.put("count", count);
		return retMap;
	}
	
	/**
	 * 消息推送
	 */
	private void pushMessage(Map<String, Object> param) throws ServiceException {
		Map<String, Object> pushInfo = null;
		Map<String, String> map_jp = Maps.newHashMap();
		try {
			pushInfo = loginLogDao.qryPushIdByUserId(param);
			if (pushInfo == null || pushInfo.isEmpty() || pushInfo.get("pushId") == null || "".equals(pushInfo.get("pushId"))) {
				return;
			}
            String pushTitle = "【微介】产品申请受理完成提醒";
            String pushContent = "您有新的产品申请已受理，请注意查收";
            // 推送
            if ("Android".equals(param.get("platform"))) {
            	// jpush
                String deviceAndro = pushInfo.get("pushId").toString();
                //push消息
//                JPushUtils.pushAndroidMessageByRegistrationID(pushTitle, pushContent, deviceAndro);
                JPushUtils.pushAndroidNotificationByRegistrationID(pushTitle, pushContent, new HashMap(),deviceAndro);
            } else {
            	String[] deviceIos = param.get("IOS").toString().split(",");
            	JPushUtils.pushIosNotificationByRegistrationID(pushContent, map_jp, deviceIos);
            }
            logger.info("消息推送成功");
		}
		catch (DaoException e) {
			logger.info("消息推送失败");
			throw new ServiceException(e.getCause());
		}
	}
	
	/**
	 * 生产订单ID
	 */
    private String getOrderId(){
    	String orderId = "";
    	@SuppressWarnings("unchecked")
		List<String> orderIdList = (List<String>) DzCache.getCacheCode("orderId");
    	if (orderIdList != null && orderIdList.get(0) != null) {
    		orderId = orderIdList.get(0);
    		orderIdList.remove(0);
		} else {
			long todayMaxorderId = DzCache.getCacheCode("todayMaxorderId") == null ? 0l :(long) DzCache.getCacheCode("todayMaxorderId");
			long maxId = todayMaxorderId + 100;
			DzCache.setCacheCode("todayMaxorderId", maxId);
			orderIdList = new ArrayList<String>();
			String strTime = DateUtil.getTimeStrFormat(new Date());
			String suffix = "00000000";
			for (long i = todayMaxorderId + 1; i < maxId + 1; i++) {
				suffix = suffix + "" + i;
				suffix = suffix.substring(suffix.length()- 8, suffix.length());
				orderIdList.add(strTime + "" + suffix);
			}
			orderId = orderIdList.get(0);
    		orderIdList.remove(0);
			DzCache.setCacheCode("orderId", orderIdList);
		}
		return orderId;
    }
    
	public class AsyncThread implements Runnable {
		private Map<String, Object> param;

		AsyncThread(Map<String, Object> param) {
			this.param = param;
		}
		@Override
		public void run() {
			try {
				pushMessage(param);
			} catch (ServiceException e) {
				e.printStackTrace();
			}
		}
	}
	
	@Override
	public List<Map<String, Object>> qryMoneyBarList(Map<String, Object> qryParam) throws ServiceException {
		List<Map<String, Object>> qryMoneyBarList = null;
		try {
			// 返回数据明细
			qryMoneyBarList = moneyBarDao.qryMoneyBarList(qryParam);
		} catch (DaoException e) {
			throw new ServiceException(e.getCause());
		}
		return qryMoneyBarList;
	}
	
	@Override
    public int auditMoneyBar(Map<String, Object> param) throws ServiceException {
    	int count = 0;
    	try {
    		count = writeMoneyBarDao.auditMoneyBar(param);
		} catch (DaoException e) {
			e.printStackTrace();
		}
    	return count;
    }
}
